package com.study.Controller;
import com.study.Model.*;

import java.security.PublicKey;
import java.util.concurrent.BlockingDeque;

public class CustomerController {

    //定义客户容器来存储信息
    private  Customer[] customers;//null
//定义客户的数量
    private int total;
//10   null
//通过set方法
//通过构造函数
public CustomerController(int length){
    customers=new Customer[length];
}
//添加用户
    public boolean  addcustomer(Customer customer){
if (customer!=null&&total<customers.length){
    customers[total++] =customer;

    return true;
}
   else{

       return false;
}
    }
    //根据用户输入的下表进行修改
    public Customer  queryCustomerByIndex(int index){

        if (index>=this.total){
            return null;
        }
        return customers[index];
    }
//修改客户
    public boolean updateCustomerByindex(int index,Customer customer){

        if (index>=this.total){
            return false;
        }
        else {
            customers[index] = customer;
            return true;
        }
    }

    //删除用户
//1 2 3 4 5 6 null null null
    public boolean delCustomerByindex(int index){
        if (index>=this.total){
            return false;
        }else {

            for (int i = index; i < total-1; i++) {
                customers[i]=customers[i+1];
            }
            customers[--total]=null;
            return true;
        }

    }
    //展示用户信息
public Customer[] zhansCustomerALL(){

    Customer[] result=new Customer[this.total];

    for (int i = 0; i < this.total; i++) {
        result[i]=customers[i];
    }
    return result;
}
}
